(function() {
  app.controller('vipPayflowCtrl', function($scope, local_m, $state, bottomdilog, tradeApi, returnData) {
    $scope.condition = [{
        head: '收/支',
        options: [
          { txt: '全部', value: '' },
          { txt: '收入', value: '0', filter: '卖出' },
          { txt: '支出', value: '1', filter: '买入' },
        ],
        default: { txt: '全部', value: '' },
      },
      {
        head: '发生日期',
        options: [
          { txt: '全部', value: 90 },
          { txt: '7天之内', value: 7 },
          { txt: '15天之内', value: 15 },
        ],
        default: { txt: '7天之内', value: 7 },
      }
    ];
    $scope.init = function() {
      $scope.rowlist = null;
      var data = returnData.dateSet($scope.condition[1].default.value, 'yyyyMMdd');
      data.funcid = '17';
      $scope.client_pay_flow(data);
    };

    $scope.client_pay_flow = function(data) {
      tradeApi
        .etQuery(data)
        .then(function(res) {
          if ($scope.condition[0].default.txt !== '全部') {
            for (var i = 0; i < res.length; i++) {
              if (res[i].bstype !== $scope.condition[0].default.filter) {
                res.splice(i, 1);
                i--;
              }
            }
          }
          angular.forEach(res, function(element) {
            if (element.occur_balance > 0) {
              element.item_a_color = 'red';
            } else {
              element.item_a_color = 'rgb(48, 174, 14)';

            }
          });
          $scope.rowList.data = res;
        });
    };

    $scope.rowList = {
      data: null,
      title: ['证券/代码', '数量/价格', '业务/金额', '日期/时间'],
      row1: [
        { key: 'stk_name' },
        { key: 'match_volume' },
        { key: 'bstype' },
        { key: 'match_date' },
      ],
      row2: [
        { key: 'stkcode' },
        { key: 'match_price' },
        { key: 'occur_balance', color_key: 'item_a_color' },
        { key: 'match_time' },
      ],
      click: function(obj) {
        console.log(obj)
      },
    }

  });

})();